The qdatastream class serializes binary data to qiodevice.
# Include
InstituteList of member functions.Public Member
Qdatastream()
Qdatastream(Qiodevice * D)
Qdatastream(Qbytearray A, int Mode)
Virtual~ Qdatastream()
Qiodevice *Device() Const
VoidSetdevice(Qiodevice
In the previous chapter, we covered the use of two classes for Qfile and Qfileinfo. We mentioned that Qiodevice provides basic operations such as read (), ReadLine (). At the same time, QT provides a higher level of operation: the flow qdatastream for binary and the Qtextstream for text flow. In this section, we will explain the use of qdatastream and some techniques. The next chapter is the relevant conten
In the previous chapter, we covered the QFile QFileInfo use of and two classes. We mentioned that it QIODevice provides read() , and readLine() so on, basic operations. At the same time, QT provides a higher level of operation: for binary streams QDataStream and for text streams QTextStream . In this section, we will explain QDataStream the use and some techniques. The next chapter is QTextStream the releva
The objects of the custom classes in MFC and Java can be persisted, and the Qt Persistence object serialization is certainly essential.But this problem really bothered me for a long time ...MFC by overriding virtual functions serialize (), Java is the class that belongs to must implement Java.io.Serializable or Externalizable interface complete,How does QT fix this thing, Qdatastream class: Let us think of MFC in the Cachive class,The Java.io.objectou
Qt provides the qfile class for file processing. To make it easier to process text files or binary files, QT also provides the qtextstream class and qdatastream class. You can use qtemporaryfile to process temporary files, you can use qfileinfo to obtain file information.To process the directory, you can use qdir. To monitor file and directory changes, you can use qfilesystemwatcher.
Read/write text filesThe qfile class provides interfaces for reading
access the device any number of times from any location, and use the QIODevice: seek () function to locate the file pointer. In terms of access methods, Qt provides two high-level abstractions: Using QDataStream for binary access and using QTextStream for text access. These classes can help us control byte sequence and text encoding, freeing programmers from this problem. QFile is very convenient for accessing independent files, whether in the file s
The objects of the custom classes in MFC and Java can be persisted, and the Qt Persistence object serialization is certainly essential.But this problem really bothered me for a long time ...MFC by overriding virtual functions serialize (), Java is the class that belongs to must implement Java.io.Serializable or Externalizable interface complete,How does QT fix this thing, Qdatastream class: Let us think of MFC in the Cachive class,The Java.io.objectou
The use of QT network communication is always simple to send data-receive data, the common is to send a string/byte stream, and then based on the string/byte stream to extract useful information. This can meet the actual needs in the communication that is not very complex. but also has the disadvantage, is every time writes the network communication is the verbal agreement one protocol, lets the sender and the receiver both satisfy this agreement can carry on the normal communication. So if ever
The meaning of a serialization operation is, by definition, saving data to a storage device in a certain order, or reading a sequence of data from a storage device, and the data type is consistent (that is, the data you read is the type I know). The process knows, how to do it?I am a simple program implemented with the help of the QT framework. (The framework, of course, implements the complex part.) If in your encapsulated data, meaning non-QT standard data types, then it is necessary to implem
Qt provides the qfile class for file processing. To make it easier to process text files or binary files, QT also provides the qtextstream class and qdatastream class. You can use qtemporaryfile to process temporary files, you can use qfileinfo to obtain file information and qdir to process directories. you can use qfilesystemwatcher to monitor file and directory changes. the qfile class for reading and writing text files provides interfaces for readi
Begin
Previously, I only summarized the UI processing of transparent, borderless, and movable windows. In order to provide some learning materials to some students, I would like to summarize some functional points.
Principle: less nonsense and more code.
Login window
Log on to tcpsocket. If you have to ask why I am not a UDP socket, I can only say that TCP is reliable.
Login
After setting the IP port, use qdatastream to write qiodevice
Void login:
); // It must be of the const char * type.
File. close ();
// QDebug ()
}
If (file. open (QIODevice: ReadOnly ))
{
QString name = "";
Double value = 0;
// The returned value of read is a QByteArray byte array. When the value is assigned to the QString variable type, the data type is automatically converted. The following statement can also be written as name = file. read (10 );
Name = QString (file. read (10 ));
File. read (reinterpret_cast
( Value), sizeof (value ));
File. close ();
Q
In the previous chapter we described the reading and writing of binary files. Binary files are small, but not human-readable formats. A text file is a human-readable file. In order to manipulate this file, we need to use QTextStream classes. QTextStream QDataStream is similar to the usage, except that it operates on plain text files. In addition, such as XML, HTML, although it is also a text file, can be QTextStream generated, but Qt provides a more c
and delete through the pointer pn
3. Use QDataStream
One of the constructors is:
QDataStream (QIODevice * d)
QIODevice describes an input/output medium that can read data from and write data to it. The QFile class is an example of an IO Device.
First, the code for opening the file is as follows:
Useless parts deleted
Void addressbookqt5vesion: rev_openfile () {QString path = qfiledision: getOpenFileName
container class store:
1
QlistMovie> movs;
The Qt container class can be QDataStream accessed directly using the. At this point, the type stored in the container must also be used QDataStream for storage. This means that we need overloads operator and operator>>() operators:
1234567891011121314151617
qdatastream
() signal connection· Using qcop can easily combine the QT signal and slot mechanism, making it very convenient to use· However, for communications between non-QT programs and QT programs, only other IPC methods can be usedQcopExample:Send messages and data in a process:
Qbytearray data;Qdatastream out ( Data, qiodevice: writeonly );Out Qcopchannel: Send ("/system/temperature", "convertceltofah (INT)", data );
Receive messages and data
Binary files are relatively small, but not readable. A text file is a readable file. to operate such a file, we need to use the QTextStream class. QTextStream is similar to QDataStream, But it operates plain text files. Some text formats, such as XML and HTML, can be generated by QTextStream, but Qt provides a more convenient XML operation class, which is not included here.
QTextStream automatically converts Unicode encoding to the same operating syst
the data end with zero octal digits, use qcstring. If the data does not end with (that is, it contains 0) octal digits, use qbytearray. If the data is text, use qstring.
You can use the qstringlist class to process the string list. You can use qstringlist: Split () to split a string into a string list, and you can use qstringlist: Join () concatenates a string list into a string with random separators. You can also use qstringlist: grep () to obtain a list of character strings from a string l
local host. If an error occurs, the error message is output and disabled.
Qdebug ()
Close ();
}
Connect (tcpserver, signal (newconnection (), this, slot (sendmessage ()));
// Connection signal and corresponding slot function
We use the listen () function of tcpserver to listen in the constructor, and then associate newconnection () with our own sendmessage () function.
The sendmessage () function is implemented below.
Voidwidget: sendmessage ()
{
Qbytearray block; // used to store the data to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.